// [物规则] 接口
import { axios } from '@/utils/request';

/**
 * [物规则] 查询指定物规则详细信息
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function getDatahubThingRule(params) {
  return axios({
    method: 'get',
    url: 'datahub/thing/rule',
    params
  })
}

/**
 * [物规则] 新增物规则
 * @params data
 * {
    {"conditionExpression":{"description":"物规则条件表达式","type":"string"}},
    {"conditions":{"description":"物规则条件","type":"array"}},
    {"description":{"description":"物规则描述","type":"string"}},
    {"extensionExpression":{"description":"物规则条件扩展表达式","type":"string"}},
    {"name":{"description":"物规则名称","type":"string"}},
    {"notifyInfoList":{"description":"物规则消息通知","type":"array"}},
    {"notifyLevel":{"description":"物规则告警等级","type":"string"}},
    {"parameters":{"description":"物规则参数","type":"array"}},
    {"pollingCron":{"description":"物规则轮询cron表达式","type":"string"}}
   }
 */
export function postDatahubThingRule(data) {
  return axios({
    method: 'post',
    url: 'datahub/thing/rule',
    data
  })
}

/**
 * [物规则] 更新物规则
 * @params data
 * {
    {"conditionExpression":{"description":"物规则条件表达式","type":"string"}},
    {"conditions":{"description":"物规则条件","type":"array"}},
    {"description":{"description":"物规则描述","type":"string"}},
    {"extensionExpression":{"description":"物规则条件扩展表达式","type":"string"}},
    {"id":{"type":"integer"}},
    {"name":{"description":"物规则名称","type":"string"}},
    {"notifyInfoList":{"description":"物规则消息通知","type":"array"}},
    {"notifyLevel":{"description":"物规则告警等级","type":"string"}},
    {"parameters":{"description":"物规则参数","type":"array"}},
    {"pollingCron":{"description":"物规则轮询cron表达式","type":"string"}}
   }
 */
export function putDatahubThingRule(data) {
  return axios({
    method: 'put',
    url: 'datahub/thing/rule',
    data
  })
}

/**
 * [物规则] 删除物规则
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function deleteDatahubThingRule(params) {
  return axios({
    method: 'delete',
    url: 'datahub/thing/rule',
    params
  })
}

/**
 * [物规则] 分页查询物规则
 * @params params
 * {
    {"name":{"required":false,"type":"string"}},
    {"userId":{"required":false,"type":"integer"}},
    {"mail":{"required":false,"type":"string"}},
    {"instanceId":{"required":false,"type":"integer"}},
    {"notifyLevel":{"required":false,"type":"string"}},
    {"pageNo":{"required":false,"type":"integer"}},
    {"pageSize":{"required":false,"type":"integer"}}
   }
 */
export function getDatahubThingRulePage(params) {
  return axios({
    method: 'get',
    url: 'datahub/thing/rule-page',
    params
  })
}

/**
 * [物规则] 查询物规则计算结果
 * @params params
 * {
    {"id":{"required":false,"type":"integer"}}
   }
 */
export function getDatahubThingRuleExecute(params) {
  return axios({
    method: 'get',
    url: 'datahub/thing/rule/execute',
    params
  })
}

/**
 * [物规则] 修改物规则状态
 * @params data
 * {
    {"id":{"description":"物规则ID","type":"integer"}},
    {"state":{"description":"物规则状态","type":"string"}}
   }
 */
export function putDatahubThingRuleState(data) {
  return axios({
    method: 'put',
    url: 'datahub/thing/rule/state',
    data
  })
}

/**
 * [物规则] 主动校验
 * @params params
 * {
    {"id":{"required":false,"type":"integer"}},
    {"field":{"required":false,"type":"string"}},
    {"value":{"required":false,"type":"object"}}
   }
 */
export function getDatahubThingRuleVerification(params) {
  return axios({
    method: 'get',
    url: 'datahub/thing/rule/verification',
    headers: { validate: true },
    params
  })
}